<?php

use Phinx\Migration\AbstractMigration;

class CreateTenantGrantAuthTable extends AbstractMigration
{
    public function up()
    {
        $this->table("tenant_grant", ['id' => false, 'primary_key' => ['id'], 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '企业授权表'])
            ->addColumn('id', 'integer', ['identity' => true, 'signed' => false, 'limit' => 11, 'comment' => '企业授权ID'])
            ->addColumn('user_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '被授权人用户id'])
            ->addColumn('tenant_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '租户id'])
            ->addColumn('status', 'enum', ['values' => 'active,disabled', 'default' => 'active', 'null' => false, 'comment' => '授权状态'])
            ->addColumn('created_by', 'integer', ['signed' => false, 'default' => 0, 'null' => false, 'limit' => 11, 'comment' => '创建者'])
            ->addColumn('created', 'integer', ['signed' => false, 'default' => 0, 'null' => false, 'limit' => 11, 'comment' => '创建时间'])
            ->addColumn('updated', 'integer', ['signed' => false, 'default' => 0, 'null' => false, 'limit' => 11, 'comment' => '更新时间'])
            ->addColumn('scope', 'text', ['null' => true, 'comment' => '授权范围'])
            ->create();
    }

    public function down()
    {
        $this->table("tenant_grant")->drop()->save();
    }
}
